package com.tencent.service.impl;/**
 * @Author King
 * @Date 2022/9/2 14:42
 * @Version 1.0.0
 */

import com.tencent.entity.Member;
import com.tencent.entity.Order;
import com.tencent.mapper.MemberYMapper;
import com.tencent.mapper.OrderMapper;
import com.tencent.service.OrderService;
import com.tencent.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @program: health2.2
 *
 * @description:
 *
 * @author: king
 *
 * @create: 2022-09-02 14:42
 **/
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    public MemberYMapper memberYMapper;
    @Autowired
    public OrderMapper orderMapper;
    @Override
    public Integer order(Map map) {
        // 是否为会员 通过手机号码查询 t_member
        String telephone = (String) map.get("telephone");
        System.out.println(telephone);
        Member member = memberYMapper.findByTelephone(telephone);
        Integer aa=0;
        if(null == member) {
            //非会员
            //   添加到会员表 获取id
            member = new Member();
            member.setIdCard((String) map.get("idCard"));
            member.setName((String) map.get("name"));
            member.setPhoneNumber(telephone);
            member.setRegTime(new Date());
            member.setSex((String) map.get("sex"));

            // 添加会员, 获取id
            memberYMapper.add(member);
        }
        aa=member.getId();
        return aa;
    }

    @Override
    public Map findById(Integer id) throws Exception {
        Map map = orderMapper.findByDetail(id);
        if (map != null){
            Date orderDate = (Date) map.get("orderDate");
            map.put("orderDate", DateUtils.parseDate2String(orderDate));
        }
        return map;
    }
}
